package com.school.service.impl;

import com.school.dao.RolePermissionMapper;
import com.school.model.RolePermission;
import com.school.model.RolePermissionExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RolePermissionServiceImpl {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private RolePermissionMapper rolePermissionMapper;

    public RolePermission queryById(Integer id) {
        RolePermissionExample rolePermissionExample = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = rolePermissionExample.createCriteria();
        criteria.andIdEqualTo(id);
        criteria.andDeletedEqualTo((byte) 0);
        List<RolePermission> rolePermissions = rolePermissionMapper.selectByExampleSelective(rolePermissionExample);
        return rolePermissions.size() == 0 ? null : rolePermissions.get(0);
    }

    public List<RolePermission> queryByRoleId(Integer roleId) {
        RolePermissionExample rolePermissionExample = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = rolePermissionExample.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        criteria.andDeletedEqualTo((byte) 0);
        return rolePermissionMapper.selectByExampleSelective(rolePermissionExample);
    }
}
